/**
 * (C) copyright geolabs 2006
 * author: Gérald Fenoy
 */

/**
 * View class
 */
System.require("XmlToJson");

OctoControler=Controler.extend();

OctoControler.define({

  _init: function(){
      this.limit=(arguments[0]&&arguments[0].limit)?arguments[0].limit:-1;
      this.tree={}; //JSON of the XML result
  },

  setView: function(view){
      this.view=view;
  },

  newData: function(){

      try{
	var test=this.request.responseXML.getElementsByTagName("error");
	var tmp=document.getElementById(this.view.errorElement);
 	//alert(this.view.errorElement+" => "+tmp);
	if(test.length>0) {
	  tmp.innerHTML="<div>"+OctoXml.serializeToString(test[0].firstChild)+"</div>";
	  return;
	}
	else{
	  if(tmp)
	    tmp.innerHTML="";
	}
      }catch(e){alert(e);return;}

      var tmp=new XmlToJson({xml: this.request.responseXML, root: this.view.root, loop: this.view.loop});
      tmp.createTree();

      this.view.update(tmp);
    }

  });
